class UserController < ApplicationController
  layout "user"
  def signup
    
  end

  def create_student
    @university         = University.find_by_stripped_name(params[:university])
    @student            = Student.create(params[:student])
    @student.university_id = @university.id
    @student.user_interests  = params[:interests]
    @verification_code= rand(9999999).to_s
    @student.verification_code  = @verification_code
    @student.save
    @recipient = params[:student][:email]
          subject = "Verify Your Account"
          message =  @verification_code
          Mailer.deliver_mail(@recipient, subject, message)
          require 'open-uri'
          require 'cgi'
         Kernel.open(CGI::unescape('http://SMSCube.AcubePro.com/SendSMS/pushsms.aspx?UserName=peyush.bansal@gmail.com&Password=cancel&SenderID=SMC&Mobile='+params[:student][:mobile_no].to_s+'&Text=Verification_Code_'+@verification_code.to_s))
        redirect_to :controller => "user", :action => "user_profile"
  end

  def create_nonstudent
      @nonstudent = NonStudent.create(params[:nonstudent])
      @verification_code= rand(9999999).to_s
      @nonstudent.verification_code  = @verification_code
      @recipient = params[:student][:email]
          subject = "Verify Your Account"
          message =  @verification_code
          Mailer.deliver_mail(@recipient, subject, message)
          require 'open-uri'
          require 'cgi'
         Kernel.open(CGI::unescape('http://SMSCube.AcubePro.com/SendSMS/pushsms.aspx?UserName=peyush.bansal@gmail.com&Password=cancel&SenderID=SMC&Mobile='+params[:student][:mobile_no].to_s+'&Text=Verification_Code_'+@verification_code.to_s))
    redirect_to :controller => "user", :action => "user_profile"
  end

  def check_email
    @email             = User.count_by_sql("select count(*) from users where email='"+params[:email]+"'")
    if @email >0
      flash[:message]="<font color=#ff0000>Email already exists. Please use a different E-mail Id or request for password! </font>"
    else
      flash[:message]="<font color=green>Email Address Available!</font>"
    end
    render  :layout=>false
  end

end
